import axios from 'axios'
import {URLPrefix} from './config'
let qs = require('qs');

let fetch = axios.create({
  headers: {
    'content-type': 'application/x-www-form-urlencoded'
  }
});

const _url = URLPrefix();
const Api = {
  post(data,url) {
    data = {
      SKEY:sessionStorage.getItem('SKEY'),
      USERID:sessionStorage.getItem('USERID'),
      ...data
    }
    let data1 = qs.stringify(Object.assign({
      BRANCHID: "555000000",
      SERVLET_NAME: "B2CMainPlat_00",
      CCB_IBSVersion: "V6",
      PT_STYLE: "10",
    }, data));
    let data2 = qs.stringify(Object.assign({
      MERCHANTID: "DEB100000000001",
      POSID: "100000001",
      BRANCHID: "441000000",
      CHARSET: "utf-8",
    }, data));
    if (url) {
      return fetch.post(url, data2)
    } else {
      return fetch.post(_url, data1)
    }
  }
}

export default Api;
